// @ts-check

/** 显示结果提示到指定容器 */
export function showResult(container, message, type) {
  const color = type === 'success' ? '#38a169' : '#e53e3e';
  container.innerHTML = `<span style="color:${color}">${message}</span>`;
  setTimeout(() => { container.innerHTML = ''; }, 2500);
}

/** 基础邮箱校验 */
export function isValidEmail(email) {
  const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return re.test(email);
}

/** 邮箱脱敏：保留前2位与域名，示例：ab****@example.com */
export function maskEmail(email) {
  if (!email || typeof email !== 'string' || !email.includes('@')) return email || '';
  const [local, domain] = email.split('@');
  const keep = Math.min(2, local.length);
  const maskedLocal = local.substring(0, keep) + '****';
  return `${maskedLocal}@${domain}`;
}